#pragma once
#include <iostream>
#include <string>
#include <vector>
#include <ctemplate/template.h>

#include "model.hpp"

namespace ns_view
{
    using namespace ns_model;
    const std::string template_path = "./template_html/";
    class View
    {
    public:
        View(){};
        ~View(){};

        void AllExpandHtml(std::vector<Question>& all, std::string* html)
        {
            std::string in_html = template_path + "all_questions.html";
            ctemplate::TemplateDictionary root("all_questions");
            for(auto& e : all)
            {
                ctemplate::TemplateDictionary* sub = root.AddSectionDictionary("question_list");
                sub->SetValue("number", e.number);
                sub->SetValue("title", e.title);
                sub->SetValue("star", e.star);
            }
            ctemplate::Template* tpl = ctemplate::Template::GetTemplate(in_html, ctemplate::DO_NOT_STRIP);
            tpl->Expand(html, &root);
        }
        void OneRxpandHtml(Question& q, std::string* html)
        {
            std::string in_html = template_path + "one_question.html";
            ctemplate::TemplateDictionary root("one_question");
            root.SetValue("number", q.number);
            root.SetValue("title", q.title);
            root.SetValue("star", q.star);
            root.SetValue("desc", q.desc);
            root.SetValue("header", q.header);
            ctemplate::Template* tpl = ctemplate::Template::GetTemplate(in_html, ctemplate::DO_NOT_STRIP);
            tpl->Expand(html, &root);
        }
    };
}